import swaggerJsdoc from 'swagger-jsdoc';
import { config } from './index.js';

const options = {
  definition: {
    openapi: '3.0.0',
    info: {
      title: '足球数据采集平台 API',
      version: '1.0.0',
      description: '足球数据采集平台的 API 文档'
    },
    servers: [
      {
        url: `http://${config.server.host}:${config.server.port}`,
        description: '开发服务器'
      }
    ],
    components: {
      schemas: {
        Match: {
          type: 'object',
          required: ['platform', 'platform_match_id', 'league_name', 'home_team', 'away_team', 'match_date'],
          properties: {
            id: {
              type: 'integer',
              description: '比赛ID'
            },
            platform: {
              type: 'string',
              description: '平台标识'
            },
            platform_match_id: {
              type: 'string',
              description: '平台比赛ID'
            },
            league_name: {
              type: 'string',
              description: '联赛名称'
            },
            home_team: {
              type: 'string',
              description: '主队'
            },
            away_team: {
              type: 'string',
              description: '客队'
            },
            match_date: {
              type: 'string',
              format: 'date-time',
              description: '比赛时间'
            },
            match_status: {
              type: 'string',
              enum: ['not_started', 'in_progress', 'finished', 'cancelled', 'postponed'],
              default: 'not_started',
              description: '比赛状态'
            },
            home_score: {
              type: 'integer',
              default: 0,
              description: '主队得分'
            },
            away_score: {
              type: 'integer',
              default: 0,
              description: '客队得分'
            },
            home_half_score: {
              type: 'integer',
              description: '主队半场得分'
            },
            away_half_score: {
              type: 'integer',
              description: '客队半场得分'
            },
            home_red_cards: {
              type: 'integer',
              default: 0,
              description: '主队红牌数'
            },
            away_red_cards: {
              type: 'integer',
              default: 0,
              description: '客队红牌数'
            },
            home_yellow_cards: {
              type: 'integer',
              default: 0,
              description: '主队黄牌数'
            },
            away_yellow_cards: {
              type: 'integer',
              default: 0,
              description: '客队黄牌数'
            },
            home_corners: {
              type: 'integer',
              default: 0,
              description: '主队角球数'
            },
            away_corners: {
              type: 'integer',
              default: 0,
              description: '客队角球数'
            },
            status: {
              type: 'string',
              enum: ['active', 'finished', 'cancelled'],
              default: 'active',
              description: '记录状态'
            },
            is_hot: {
              type: 'boolean',
              default: false,
              description: '是否热门'
            },
            is_recommended: {
              type: 'boolean',
              default: false,
              description: '是否推荐'
            },
            tags: {
              type: 'array',
              items: {
                type: 'string'
              },
              description: '标签'
            },
            note: {
              type: 'string',
              description: '备注'
            },
            created_at: {
              type: 'string',
              format: 'date-time',
              description: '创建时间'
            },
            updated_at: {
              type: 'string',
              format: 'date-time',
              description: '更新时间'
            }
          }
        },
        MatchResponse: {
          type: 'object',
          properties: {
            success: {
              type: 'boolean'
            },
            data: {
              $ref: '#/components/schemas/Match'
            }
          }
        },
        MatchListResponse: {
          type: 'object',
          properties: {
            success: {
              type: 'boolean'
            },
            data: {
              type: 'object',
              properties: {
                total: {
                  type: 'integer',
                  description: '总记录数'
                },
                items: {
                  type: 'array',
                  items: {
                    $ref: '#/components/schemas/Match'
                  }
                },
                page: {
                  type: 'integer',
                  description: '当前页码'
                },
                limit: {
                  type: 'integer',
                  description: '每页数量'
                }
              }
            }
          }
        },
        Odds: {
          type: 'object',
          properties: {
            matchId: { type: 'string', description: '比赛ID' },
            platform: { type: 'string', description: '平台标识' },
            type: {
              type: 'string',
              enum: ['asian_handicap', 'european', 'over_under', 'correct_score', 'half_full'],
              description: '赔率类型'
            },
            odds: {
              type: 'object',
              description: '赔率数据'
            }
          }
        },
        Error: {
          type: 'object',
          properties: {
            error: { type: 'string', description: '错误信息' }
          }
        }
      },
      responses: {
        Error: {
          description: '错误响应',
          content: {
            'application/json': {
              schema: {
                $ref: '#/components/schemas/Error'
              }
            }
          }
        }
      }
    }
  },
  apis: ['./src/routes/*.js']
};

export const specs = swaggerJsdoc(options); 